package spring.boot.demo.cloudconfigclient.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

//@RefreshScope // 使用该注解的类，会在接到SpringCloud配置中心配置刷新的时候，自动将新的配置更新到该类对应的字段中。
@RestController("/test")
public class TestController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Value("${neo.hello}")
    private String hello;

    @Value("#{configProperties['neo-config-dev.neo.hello']}")
    private String hello2;


    @RequestMapping("/hello")
    public String from() {
        return this.hello;
    }

    @RequestMapping("/redis/set")
    public String redisset(String key,String value) {
        stringRedisTemplate.opsForValue().set(key,value,5, TimeUnit.MINUTES);
        return "set ok";
    }

    @RequestMapping("/redis/get")
    public String redisset(String key) {
        String value = stringRedisTemplate.opsForValue().get(key);
        return "get value="+value;
    }

    @RequestMapping("/hello2")
    public String hello2(String key) {
        return this.hello2;
    }
}
